// 全局请求封装
export default (url, method, params) => {
const baseUrl = 'https://publish.onedaen.com'
const userInfo=uni.getStorageSync('userInfo')
const token = userInfo.token
const uid= userInfo.uid
let header = {
	'token':token,
	'uid':uid
};
	// uni.showLoading({ title: '加载中' })
	/* if(!token ){
		console.log(555)
		// 执行没有登录的逻辑
		return
	} */
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			method: method,
			header:  header , // 设置token，请根据实际情况判断是否要设置
			data: { ...params },
			timeout:10000,
			success(res) {
                console.log('响应拦截器succeess接口返回:', res)
               if (res.data.code == 401) {
               	// 如果后端返回401无权限，则本地同步删除缓存(token等信息)
               	uni.showModal({
               	  title: '请登录后查看',
               	  success: (res) => {
               	    console.log('res', res)
               	    if (res.confirm) {
               	      
               	    }
               	  },
               	})
                   uni.clearStorageSync()
                   resolve(res.data)	
               } else if(res.code==false){
               	uni.showModal({
               	  title: '请登录后查看',
               	  success: (res) => {
               	    console.log('res', res)
               	    if (res.confirm) {
               	      
               	    }
               	  },
               	})
               	return
               }else{
               	resolve(res.data)
               }
			},
			fail(err) {
				reject(err)
			},
			complete() {
				uni.hideLoading()
			}
		})
	})
}

